<?php
/**
 * 购买
 *
 *
 *
 *
 
 */

//use Shopnc\Tpl;

defined('InShopNC') or exit('Access Invalid!');

class member_buyControl extends mobileMemberControl {

	public function __construct() {
		parent::__construct();
	}
	
	/**
	 * 2016-12-09
	 * 返回是否促销商品
	 * @param unknown $goods_id 商品ID
	 */
	private function _is_discount($goods_id)
	{
	    //获得每一件购物车商品是否是促销商品
	    //$value['goods_id']
	    $model_goods = Model('goods');
	    $goods_info=$model_goods->getGoodsOnlineInfoForShare($goods_id);
	    return $goods_info['is_discount'];
	    //return $goods_info;
	}

    /**
     * 购物车、直接购买第一步:选择收获地址和配置方式
     */
    public function buy_step1Op() {
       //先判断是否是促销商品，而且已经够买过该促销商品
       if(!$_POST['ifcart']){//判断是否是直接购买
           $cart_id = explode('|', $_POST['cart_id']);

           //$_POST['goods_id']
           $is_discount=$this->_is_discount($cart_id[0]);
           //获得用户id
           $condition['buyer_id'] = $this->member_info['member_id'];
           if($is_discount){
               //查看购物车是否有该商品
               $cart=Model('cart');
               $condition1['goods_id']=$cart_id[0];//商品id
               $condition1['buyer_id']=$condition['buyer_id'];
               $result=$cart->getCartInfo($condition1);
               //var_export($result);die;
               if($result){
                   //有该商品，删除该商品
                   $condition2['cart_id']=$result['cart_id'];
                   $cart->delCart('db',$condition2);
                   
               }
               
               //判断以往是否购买过该商品
               $order=Model('order');
               
               //获得商品id
               $condition['goods_id'] = $cart_id[0];
               //获得数组
               $result=$order->get_oeder_good($condition);
               if ($result['goods_id']){
                   output_error('您已购买过该促销商品!');
               }
           }
       }
       

        $goods=Model('order');  
        $cart_id = explode(',', $_POST['cart_id']);
        $logic_buy = logic('buy');
        //得到购买数据
        //只是作为拼团价格写入，若不是拼团，则为0
        $groupbuy_price=0;
        $result = $logic_buy->buyStep1($groupbuy_price,$cart_id, $_POST['ifcart'], $this->member_info['member_id'], $this->member_info['store_id']);
        /* echo '<pre>';
        var_export($result);die; */
        $get_voucher_id=$result['data']['store_voucher_list'];
        //临时保存优惠券列表
        $temp_voucher_list=$result['data']['store_voucher_list'];
        //echo json_encode($temp_voucher_list);die;
        if(!$result['state']) {
            output_error($result['msg']);
        } else {
            $result = $result['data'];
        }
        
        //整理数据
        $store_cart_list = array();
        foreach ($result['store_cart_list'] as $key => $value) {
            $store_cart_list[$key]['goods_list'] = $value;
            $store_cart_list[$key]['store_goods_total'] = $result['store_goods_total'][$key];
            if(!empty($result['store_premiums_list'][$key])) {
                $result['store_premiums_list'][$key][0]['premiums'] = true;
                $result['store_premiums_list'][$key][0]['goods_total'] = 0.00;
                $store_cart_list[$key]['goods_list'][] = $result['store_premiums_list'][$key][0];
            }
            $store_cart_list[$key]['store_mansong_rule_list'] = $result['store_mansong_rule_list'][$key];
            $store_cart_list[$key]['store_voucher_list'] = $result['store_voucher_list'][$key];
            if(!empty($result['cancel_calc_sid_list'][$key])) {
                $store_cart_list[$key]['freight'] = '0';
                $store_cart_list[$key]['freight_message'] = $result['cancel_calc_sid_list'][$key]['desc'];
            } else {
                $store_cart_list[$key]['freight'] = '1';
            }
            $store_cart_list[$key]['store_name'] = $value[0]['store_name'];
        }

        $member_id=$this->member_info['member_id'];
        $member_data = Model('member')->getMemberInfoByID($member_id);
        $point_exchange = Model('setting')->getRowSetting('point_exchange');
        $buy_list = array();
        $buy_list['store_cart_list'] = $store_cart_list;
        $buy_list['freight_hash'] = $result['freight_list'];
        $buy_list['address_info'] = $result['address_info'];
        $buy_list['freight_total'] = $result['freight_total'];
        $buy_list['goods_freight'] = $result['per_goods_freight'];
        $buy_list['ifshow_offpay'] = $result['ifshow_offpay'];
        $buy_list['deny_edit_payment'] = $result['deny_edit_payment'];
        $buy_list['allow_offpay'] = $result['allow_offpay'];
        $buy_list['allow_offpay_batch'] = $result['allow_offpay_batch'];
        $buy_list['offpay_hash'] = $result['offpay_hash'];
        $buy_list['offpay_hash_batch'] = $result['offpay_hash_batch'];

        $buy_list['vat_hash'] = $result['vat_hash'];
        $buy_list['inv_info'] = $result['inv_info'];
        $buy_list['available_predeposit'] = $result['available_predeposit'];
        $buy_list['available_rc_balance'] = $result['available_rc_balance'];
        $buy_list['member_point'] = $member_data['member_points'];
        $buy_list['point_exchange'] = $point_exchange['value'];
        /* $voucherlist=Model('voucher')->getCurrentAvailableVoucher_t_id(array('voucher_owner_id'=>$this->member_info['member_id']));
        //echo json_encode($voucherlist);die;
        $v_t_id='';
        foreach ($voucherlist as $k=> $v) {
            $v_t_id.= $v['voucher_t_id'].',';
            //echo $v['voucher_t_id'].',';
        }

        $v_t_id=rtrim($v_t_id, ",");
        $buy_list['v_t_id'] = $v_t_id; */
        
        $v_t_id='';
         /* echo '<pre>';
        var_export($temp_voucher_list);die; */ 
        
         foreach ($temp_voucher_list as $k=> $v) {//店铺
            //echo $k.'<br>';
            foreach ($v as $tvl => $tvlv){//代金券内容
                //echo $tvl.'<br>';
                $v_t_id.= $tvlv['voucher_t_id'].',';
                
            }
            //echo $v['voucher_t_id'].',';
        } 
       
       
        $v_t_id=rtrim($v_t_id, ",");
        $buy_list['v_t_id'] = $v_t_id;
        
        $buy_list['is_pick'] = $result['is_pick'];
        if($result['is_pick']) {
            $setting = Model("setting")->getListSetting();
            $buy_list['pick_address'] = $setting['delivery_area_info'].$setting['delivery_address'];
        }
        output_data($buy_list);
    }

    /**
     * 购物车、直接购买第二步:保存订单入库，产生订单号，开始选择支付方式
     *
     */
    public function buy_step2Op() {
        
        $param = array();
        $param['ifcart'] = $_POST['ifcart'];
        $param['is_pick'] = $_POST['is_pick'];
        $param['cart_id'] = explode(',', $_POST['cart_id']);
        $param['address_id'] = $_POST['address_id'];
        $param['vat_hash'] = $_POST['vat_hash'];
        $param['offpay_hash'] = $_POST['offpay_hash'];
        $param['offpay_hash_batch'] = $_POST['offpay_hash_batch'];
        $param['pay_name'] = $_POST['pay_name'];
        $param['invoice_id'] = $_POST['invoice_id'];
       
        //处理代金券
        $voucher = array();
        $post_voucher = explode(',', $_POST['voucher']);
        if(!empty($post_voucher)) {
            foreach ($post_voucher as $value) {
                list($voucher_t_id, $store_id, $voucher_price) = explode('|', $value);
                $voucher[$store_id] = $value;
            }
        }
        $param['voucher'] = $voucher;

        //手机端暂时不做支付留言，页面内容太多了
        //$param['pay_message'] = json_decode($_POST['pay_message']);
        $param['pd_pay'] = $_POST['pd_pay'];
        $param['rcb_pay'] = $_POST['rcb_pay'];
        $param['password'] = $_POST['password'];
        $param['fcode'] = $_POST['fcode'];
        $param['order_from'] = 2;
        $logic_buy = logic('buy');

        $result = $logic_buy->buyStep2($param, $this->member_info['member_id'], $this->member_info['member_name'], $this->member_info['member_email']);
        //output_data($result);
        if(!$result['state']) {
            output_error($result['msg']);
        }

        output_data(array('pay_sn' => $result['data']['pay_sn']));
    }

    /**
     * 验证密码
     */
    public function check_passwordOp() {
        if(empty($_POST['password'])) {
            output_error('参数错误');
        }

        $model_member = Model('member');

        $member_info = $model_member->getMemberInfoByID($this->member_info['member_id']);
        if($member_info['member_paypwd'] == md5($_POST['password'])) {
            output_data('1');
        } else {
            output_error('密码错误');
        }
    }

    /**
     * 更换收货地址
     */
    public function change_addressOp() {
        $logic_buy = Logic('buy');
        $data = $logic_buy->changeAddr($_POST['freight_hash'], $_POST['city_id'], $_POST['area_id'], $this->member_info['member_id']);
        if(!empty($data) && $data['state'] == 'success' ) {
            output_data($data);
        } else {
            output_error('地址修改失败');
        }
    }
    
    
    /*
     * 团长开团
     */
    public function start_a_teamOp(){
        //首先获得用户登录标记key
        //先判断是否已经开团过了
        $groupbuy_team_model=Model('groupbuy_team');
        $where['groupbuy_id']=$_POST['groupbuy_id'];
        $where['lead_id']=$this->member_info['member_id'];
        $data['pay_status']=array('gt',0);
        $count_info=$groupbuy_team_model->check_team($where);
        if (!empty($count_info) && $count_info['team_number']=$count_info['record_num']){
            output_error('同一商品只能开一个拼团');
        }
        /* if($count){
            output_error('只能开一个拼团');
        } */
    
        //获得团购活动id
        $data['groupbuy_id']=$condition1['groupbuy_id']=$_POST['groupbuy_id'];
        $data['goods_id']=$_POST['goods_id'];
        $data1['member_id']=$data['lead_id']=$this->member_info['member_id'];
        $data['lead_name']=$this->member_info['member_name'];
        //team_number从团购活动模板找
        $groupbuy_team_template_model=Model('groupbuy_team_template');
        $team_template=$groupbuy_team_template_model->get_template($condition1);
        $data['team_number']=$team_template['team_template_num'];
        $data['record_num']=0;
        $data['start_time']=TIMESTAMP;
        //结束时间，要从groupbuy表里找
        $groupbuy_model=Model('groupbuy');
        $groupbuy_info=$groupbuy_model->getGroupbuyOnlineInfo($condition1);
        $data['end_time']=$groupbuy_info['end_time'];
        $data['pay_status']=0;
        //先保存数据到team表里
        $groupbuy_team_model=Model('groupbuy_team');
        /* echo '<pre>';
        var_export($data);die; */
        $result=$groupbuy_team_model->save_team($data);
        //在保存数据到mem表里
        if($result){
            //$data1['member_id']=$this->member_info['member_id'];
            $data1['team_id']=$result;
            $data1['lead_flag']=1;
            $data1['member_price']=$team_template['team_template_lead_price'];
            $groupbuy_mem_model=Model('groupbuy_mem');
            $result1=$groupbuy_mem_model->save_mem($data1);
            if ($result1){
                $data2['cart_id']=$_POST['cart_id'];
                //加一个参数，拼团价格
                $groupbuy_price=$data1['member_price'];
                $buy_list=$this->groupbuy_buy_step1($data2,$groupbuy_price);
                //goods_list

                foreach ($buy_list as $key =>$val){
                     foreach ($val as $key2 =>$val2){
                        foreach ($val2 as $key3=>$val3){
                             foreach ($val3 as $key4=>$val4){
                                $buy_list[$key][$key2][$key3][$key4]['goods_group_price']=$data1['member_price'];
                                break;
                            }  
                            break;
                        }
                        break;
                    } 
                    break;
                }
                //把team_id保存起来，作为标记
                $buy_list['team_id']=$data1['team_id'];
                //$buy_list['store_voucher_list']=null;
                output_data($buy_list);
                //重新操作数据


            }else{
                $where['team_id']=$result;
                $result2=$groupbuy_team_model->delet_team($where);
                if ($result2){
                    output_error('系统繁忙,开团失败err');
                }else{
                    $groupbuy_team_model->delet_team($where);
                    output_error('系统繁忙,请等待');
                }
                
            }
        }else{
            output_error('系统繁忙,开团失败');
        }
    
    
    }
    
    public function temp_team_start(){

        //首先获得用户登录标记key
        //先判断是否已经开团过了
        $groupbuy_team_model=Model('groupbuy_team');
        $where['groupbuy_id']=$_POST['groupbuy_id'];
        $where['lead_id']=$this->member_info['member_id'];
        $data['pay_status']=array('gt',0);
        $count_info=$groupbuy_team_model->check_team($where);
        if (!empty($count_info) && $count_info['team_number']=$count_info['record_num']){
            output_error('同一商品只能开一个拼团');
        }
        /* if($count){
         output_error('只能开一个拼团');
         } */
        
        //获得团购活动id
        $data['groupbuy_id']=$condition1['groupbuy_id']=$_POST['groupbuy_id'];
        $data['goods_id']=$_POST['goods_id'];
        $data1['member_id']=$data['lead_id']=$this->member_info['member_id'];
        $data['lead_name']=$this->member_info['member_name'];
        //team_number从团购活动模板找
        $groupbuy_team_template_model=Model('groupbuy_team_template');
        $team_template=$groupbuy_team_template_model->get_template($condition1);
        $data['team_number']=$team_template['team_template_num'];
        $data['record_num']=0;
        $data['start_time']=TIMESTAMP;
        //结束时间，要从groupbuy表里找
        $groupbuy_model=Model('groupbuy');
        $groupbuy_info=$groupbuy_model->getGroupbuyOnlineInfo($condition1);
        $data['end_time']=$groupbuy_info['end_time'];
        $data['pay_status']=0;
        //先保存数据到team表里
        $groupbuy_team_model=Model('groupbuy_team');
        /* echo '<pre>';
         var_export($data);die; */
        $result=$groupbuy_team_model->save_team($data);
        //在保存数据到mem表里
        if($result){
            //$data1['member_id']=$this->member_info['member_id'];
            $data1['team_id']=$result;
            $data1['lead_flag']=1;
            $data1['member_price']=$team_template['team_template_lead_price'];
            $groupbuy_mem_model=Model('groupbuy_mem');
            $result1=$groupbuy_mem_model->save_mem($data1);
            if ($result1){
                $data2['cart_id']=$_POST['cart_id'];
                //加一个参数，拼团价格
                $groupbuy_price=$data1['member_price'];
                $buy_list=$this->groupbuy_buy_step1($data2,$groupbuy_price);
                //goods_list
        
                foreach ($buy_list as $key =>$val){
                    foreach ($val as $key2 =>$val2){
                        foreach ($val2 as $key3=>$val3){
                            foreach ($val3 as $key4=>$val4){
                                $buy_list[$key][$key2][$key3][$key4]['goods_group_price']=$data1['member_price'];
                                break;
                            }
                            break;
                        }
                        break;
                    }
                    break;
                }
                //把team_id保存起来，作为标记
                $buy_list['team_id']=$data1['team_id'];
                //$buy_list['store_voucher_list']=null;
                output_data($buy_list);
                //重新操作数据
        
        
            }else{
                $where['team_id']=$result;
                $result2=$groupbuy_team_model->delet_team($where);
                if ($result2){
                    output_error('系统繁忙,开团失败err');
                }else{
                    $groupbuy_team_model->delet_team($where);
                    output_error('系统繁忙,请等待');
                }
        
            }
        }else{
            output_error('系统繁忙,开团失败');
        }
        
        
        
    }
    
    
    /**
     * 购物车、直接购买第一步:选择收获地址和配置方式
     */
    private function groupbuy_buy_step1($data,$groupbuy_price) {

        $cart_id = explode(',', $_POST['cart_id']);
    
        $logic_buy = logic('buy');
    
        //得到购买数据
        $result = $logic_buy->buyStep1($groupbuy_price,$cart_id, 0, $this->member_info['member_id'], $this->member_info['store_id']);
        if(!$result['state']) {
            output_error($result['msg']);
        } else {
            $result = $result['data'];
        }
    
        //整理数据
        $store_cart_list = array();
        foreach ($result['store_cart_list'] as $key => $value) {
            $store_cart_list[$key]['goods_list'] = $value;
            $store_cart_list[$key]['store_goods_total'] = $result['store_goods_total'][$key];
            if(!empty($result['store_premiums_list'][$key])) {
                $result['store_premiums_list'][$key][0]['premiums'] = true;
                $result['store_premiums_list'][$key][0]['goods_total'] = 0.00;
                $store_cart_list[$key]['goods_list'][] = $result['store_premiums_list'][$key][0];
            }
            $store_cart_list[$key]['store_mansong_rule_list'] = $result['store_mansong_rule_list'][$key];
            $store_cart_list[$key]['store_voucher_list'] = $result['store_voucher_list'][$key];
            if(!empty($result['cancel_calc_sid_list'][$key])) {
                $store_cart_list[$key]['freight'] = '0';
                $store_cart_list[$key]['freight_message'] = $result['cancel_calc_sid_list'][$key]['desc'];
            } else {
                $store_cart_list[$key]['freight'] = '1';
            }
            $store_cart_list[$key]['store_name'] = $value[0]['store_name'];
        }
    
        $member_id=$this->member_info['member_id'];
        $member_data = Model('member')->getMemberInfoByID($member_id);
        $point_exchange = Model('setting')->getRowSetting('point_exchange');
        $buy_list = array();
        $buy_list['store_cart_list'] = $store_cart_list;
        $buy_list['freight_hash'] = $result['freight_list'];
        $buy_list['address_info'] = $result['address_info'];
        $buy_list['freight_total'] = $result['freight_total'];
        $buy_list['ifshow_offpay'] = $result['ifshow_offpay'];
        $buy_list['deny_edit_payment'] = $result['deny_edit_payment'];
        $buy_list['allow_offpay'] = $result['allow_offpay'];
        $buy_list['allow_offpay_batch'] = $result['allow_offpay_batch'];
        $buy_list['offpay_hash'] = $result['offpay_hash'];
        $buy_list['offpay_hash_batch'] = $result['offpay_hash_batch'];
    
        $buy_list['vat_hash'] = $result['vat_hash'];
        $buy_list['inv_info'] = $result['inv_info'];
        $buy_list['available_predeposit'] = $result['available_predeposit'];
        $buy_list['available_rc_balance'] = $result['available_rc_balance'];
        $buy_list['member_point'] = $member_data['member_points'];
        $buy_list['point_exchange'] = $point_exchange['value'];
        $voucherlist=Model('voucher')->getCurrentAvailableVoucher_t_id(array('voucher_owner_id'=>$this->member_info['member_id']));
        //echo json_encode($voucherlist);die;
        $v_t_id='';
        foreach ($voucherlist as $k=> $v) {
            $v_t_id.= $v['voucher_t_id'].',';
            //echo $v['voucher_t_id'].',';
        }
        $v_t_id=rtrim($v_t_id, ",");
        $buy_list['v_t_id'] = $v_t_id;
    
        $buy_list['is_pick'] = $result['is_pick'];
        if($result['is_pick']) {
            $setting = Model("setting")->getListSetting();
            $buy_list['pick_address'] = $setting['delivery_area_info'].$setting['delivery_address'];
        }
        return $buy_list;
        //output_data($buy_list);
    }
    
    
    /**
     * 购物车、直接购买第二步:保存订单入库，产生订单号，开始选择支付方式
     *
     */
    public function groupbuy_buy_step2Op() {
    
        /*
         * 拼团操作
         */
        //先判断是否已经开团过了
        $groupbuy_team_model=Model('groupbuy_team');
        $where['groupbuy_id']=$_POST['groupbuy_id'];
        $where['lead_id']=$this->member_info['member_id'];
        $data['pay_status']=array('gt',0);
        $count_info=$groupbuy_team_model->check_team($where);
        if (!empty($count_info) && $count_info['team_number']=$count_info['record_num']){
            output_error('同一商品只能开一个拼团');
        }
        
        //获得团购活动id
        $data['groupbuy_id']=$condition1['groupbuy_id']=$_POST['groupbuy_id'];
        $data['goods_id']=$_POST['goods_id'];
        $data1['member_id']=$data['lead_id']=$this->member_info['member_id'];
        $data['lead_name']=$this->member_info['member_name'];
        //team_number从团购活动模板找
        $groupbuy_team_template_model=Model('groupbuy_team_template');
        $team_template=$groupbuy_team_template_model->get_template($condition1);
        $data['team_number']=$team_template['team_template_num'];
        $data['record_num']=0;
        $data['start_time']=TIMESTAMP;
        //结束时间，要从groupbuy表里找
        $groupbuy_model=Model('groupbuy');
        $groupbuy_info=$groupbuy_model->getGroupbuyOnlineInfo($condition1);
        $data['end_time']=$groupbuy_info['end_time'];
        $data['pay_status']=0;
        //先保存数据到team表里
        $groupbuy_team_model=Model('groupbuy_team');
        /* echo '<pre>';
         var_export($data);die; */
        $result=$groupbuy_team_model->save_team($data);
        
        //在保存数据到mem表里
        if($result){
            //$data1['member_id']=$this->member_info['member_id'];
            $data1['team_id']=$result;
            $data1['lead_flag']=1;
            $data1['member_price']=$team_template['team_template_lead_price'];
            $groupbuy_mem_model=Model('groupbuy_mem');
            $result1=$groupbuy_mem_model->save_mem($data1);
            if ($result1){
                
                //$data2['cart_id']=$_POST['cart_id'];
                //加一个参数，拼团价格
                //$groupbuy_price=$data1['member_price'];
                //$buy_list=$this->groupbuy_buy_step1($data2,$groupbuy_price);
                $param = array();
                $param['ifcart'] = $_POST['ifcart'];
                $param['is_pick'] = $_POST['is_pick'];
                $param['cart_id'] = explode(',', $_POST['cart_id']);
                $param['address_id'] = $_POST['address_id'];
                $param['vat_hash'] = $_POST['vat_hash'];
                $param['offpay_hash'] = $_POST['offpay_hash'];
                $param['offpay_hash_batch'] = $_POST['offpay_hash_batch'];
                $param['pay_name'] = $_POST['pay_name'];
                $param['invoice_id'] = $_POST['invoice_id'];
                //team_id作为拼团标记
                $param['team_id'] = $result;
                //拼团总金额
                $param['store_goods_total'] = $_POST['goods_group_price'];
                //处理代金券
                $voucher = array();
                $post_voucher = explode(',', $_POST['voucher']);
                if(!empty($post_voucher)) {
                    foreach ($post_voucher as $value) {
                        list($voucher_t_id, $store_id, $voucher_price) = explode('|', $value);
                        $voucher[$store_id] = $value;
                    }
                }
                $param['voucher'] = $voucher;
                
                //手机端暂时不做支付留言，页面内容太多了
                //$param['pay_message'] = json_decode($_POST['pay_message']);
                $param['pd_pay'] = $_POST['pd_pay'];
                $param['rcb_pay'] = $_POST['rcb_pay'];
                $param['password'] = $_POST['password'];
                $param['fcode'] = $_POST['fcode'];
                $param['order_from'] = 2;
                $logic_buy = logic('buy');
                
                $result = $logic_buy->buyStep2($param, $this->member_info['member_id'], $this->member_info['member_name'], $this->member_info['member_email']);
                //output_data($result);
                if(!$result['state']) {
                    output_error($result['msg']);
                }
                
                //2017-02-06在这里把价格改了，可以不可以呢？
                
                output_data(array('pay_sn' => $result['data']['pay_sn']));
            }else{
                //成员表写入失败
                $where['team_id']=$result;
                $result2=$groupbuy_team_model->delet_team($where);
                if ($result2){
                    output_error('系统繁忙,开团失败err');
                }else{
                    $groupbuy_team_model->delet_team($where);
                    output_error('系统繁忙,请等待');
                }
                
            }
            
        }else{
            //拼团表写入失败
            output_error('系统繁忙,开团失败');
        }
        /*
         * 拼团操作
         */
        
        
    }
    
    
    
    /*
     * 参团
     */
    public function join_a_teamOp(){
        //拼团id
        $data['team_id']=$_POST['team_id'];
        $data['member_id']=$this->member_info['member_id'];
        $data['pay_status']=array('gt',0);
        //判断用户是否参加过该team
        $groupbuy_mem_model=Model('groupbuy_mem');
        $count=$groupbuy_mem_model->check_mem_join($data);
        if($count){
            output_error('您已参加过该拼团');
        }
        unset($data['pay_status']);
        $data['lead_flag']=0;
        $data['member_price']=0;
    
        $groupbuy_team_template_model=Model('groupbuy_team_template');
        $condition['groupbuy_id']=$_POST['groupbuy_id'];
        $team_template=$groupbuy_team_template_model->get_template($condition);
        $data['member_price']=$team_template['team_template_member_price'];
        $data['pay_status']=0;
        $groupbuy_mem_model=Model('groupbuy_mem');
        $result=$groupbuy_mem_model->save_mem($data);
        if ($result){
            $data=$_POST['cart_id'];
            $groupbuy_price=$data['member_price'];
            $buy_list=$this->groupbuy_buy_step1($data,$groupbuy_price);
            foreach ($buy_list as $key =>$val){
                foreach ($val as $key2 =>$val2){
                    foreach ($val2 as $key3=>$val3){
                        $buy_list[$key][$key2][$key3]['goods_group_price']=$data['member_price'];
                    }
                }
            }
            $buy_list['team_id']=$data['team_id'];
            output_data($buy_list);
            //设置跳转到付款
            //output_data(array('msg'=>'参团成功'));
        }else{
            output_error('参团失败');
        }
    
    }


}

